public class Student {
    public String name;
    public int age;
    //当成员变量使用static修饰时，为所有对象所公用，不存在与对象当中直接类名.方法赋值即可
    private static String classRoom = "109";
    //示例代码块，对象被创建时才会调用
    {
        this.name = "annie";
        this.age = 19;
        System.out.println("示例代码块");
    }
    //静态代码块，类创建时创建，只执行一次
    static {
        classRoom = "105";
        System.out.println("静态代码块");
    }

    public static String getClassRoom() {
        return classRoom;
    }

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public static void main(String[] args) {
//        Student s1 = new Student("zhangsan",2);
//        Student s2 = new Student("lisi" , 3);
//        Student.classRoom = "109";
        Student student = new Student();
        System.out.println(student.age);
        System.out.println(student.name);
    }
}
class Test{
    public static void test(){
        //test1();      静态方法无法直接调用非静态方法
        Test test = new Test();
        test.test1();   //但可以通过对象的引用去调用
    }
    public void test1(){
    }
    //如何调用Student中的private属性的classRoom？
    public static void main(String[] args) {
        //通过get方法即可，静态成员通过静态方法调用，无需创建对象，通过类名调用即可
        System.out.println(Student.getClassRoom());
        Test test = null;
        test.test1();
    }
}
